package num70;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/4/13 23:55
 * @Desc :
 */
public class Solution {
  public int climbStairs0(int n) {
    if (n <= 1) return 1;
    int[] status = new int[n];
    status[0] = 1;
    status[1] = 2;
    for (int i = 2; i < n; i++) {
      status[i] = status[i - 1] + status[i - 2];
    }
    return status[n-1];
  }
  public int climbStairs(int n) {
    if (n <= 1) return 1;
    int prev1 = 2;
    int prev2 = 1;
    for (int i = 2; i < n; i++) {
      int temp = prev2;
      prev2 = prev1;
      prev1 = prev2 + temp;
    }
    return prev1;
  }

  public static void main(String[] args) {
    int res = new Solution().climbStairs(2);
    System.out.println(res);
  }
}
